namespace org.lionsoul.ip2region
{

    /// <summary>
    /// header block class
    /// 
    /// @author chenxin<chenxin619315@gmail.com>
    /// </summary>
    public class HeaderBlock
    {
        /// <summary>
        /// index block start ip address
        /// </summary>
        private long indexStartIp;

        /// <summary>
        /// ip address 
        /// </summary>
        private int indexPtr;

        public HeaderBlock(long indexStartIp, int indexPtr)
        {
            this.indexStartIp = indexStartIp;
            this.indexPtr = indexPtr;
        }

        public virtual long IndexStartIp
        {
            get
            {
                return indexStartIp;
            }
        }

        public virtual HeaderBlock setIndexStartIp(long indexStartIp)
        {
            this.indexStartIp = indexStartIp;
            return this;
        }

        public virtual int IndexPtr
        {
            get
            {
                return indexPtr;
            }
        }

        public virtual HeaderBlock setIndexPtr(int indexPtr)
        {
            this.indexPtr = indexPtr;
            return this;
        }

        /// <summary>
        /// get the bytes for db storage
        /// </summary>
        /// <returns>    byte[] </returns>
        public virtual byte[] Bytes
        {
            get
            {
                /*
                 * +------------+-----------+
                 * | 4bytes        | 4bytes    |
                 * +------------+-----------+
                 *  start ip      index ptr
                */
                byte[] b = new byte[8];

                Util.writeIntLong(b, 0, indexStartIp);
                Util.writeIntLong(b, 4, indexPtr);

                return b;
            }
        }
    }
}